//import mapJs from '../lib/maps.js'
import {Et} from "./Oak.js";
var map = null;
var marker;
 let iconMap = {
	"MONITOR_RAIN": require("@/assets/images/point/monitor_rain.png"),
	"MONITOR_SW": require("@/assets/images/point/monitor_sw.png"),
	"MONITOR_REO": require("@/assets/images/point/monitor_reo.png"),
	"MONITOR_RIVER": require("@/assets/images/point/monitor_river.png"),
	"MONITOR_PIPE": require("@/assets/images/point/monitor_pipe.png"),
	"MONITOR_WATER": require("@/assets/images/point/monitor_water.png"),
 }
export default {
	
	
	initMap(){
		map = new AMap.Map('map', {
		 resizeEnable: true,
		 zoom:22,//级别
		 center: [113.115622, 23.043764],//中心点坐标
		 viewMode:'3D'//使用3D视图
		});
		AMap.plugin([
		    'AMap.ToolBar'
		], function(){
		    // 在图面添加工具条控件，工具条控件集成了缩放、平移、定位等功能按钮在内的组合控件
		    map.addControl(new AMap.ToolBar({ position: "LT",liteStyle: true}));
		});
	},
	
	//请求接口渲染的地图数据
	randerMarker(locationList){
		let addMarkerList,images;
		map.clearMap(); //清除marker
		addMarkerList = locationList.features.map(item => {
			let { coordinates } = item.geometry
			let { properties } = item
			let lgt = coordinates[0],lat = coordinates[1]
			if(!isNaN(Number(lgt)) && !isNaN(Number(lat))){				
				images = new AMap.Icon({
					size: new AMap.Size(30, 34),
					image: iconMap[locationList.layerId],
					imageSize: new AMap.Size(30, 30),
				});
				// marker = []
				marker = new AMap.Marker({
					position: [lgt * 1,lat * 1],
					icon:  images,
				})
                let title = '';
				// if(equipName){
				// 	title = equipName
				// }else{
				// 	title = equipCode + '_' +alarmTitle
				// }
				marker.on('click', function(e) {
							Et.Manager.dispatch("pointChange",properties,locationList.layerId)
					// addMarkerList.forEach(item => {
					// 	item.setLabel({
					// 		content: "", //设置文本标注内容
					// 		direction: 'top' //设置文本标注方位
					// 	});
					// })
					// this.setLabel({
					// 	 offset: new AMap.Pixel(0, -10),  //设置文本标注偏移量
					// 	content: "<div class='info'>"+title+"<i></i></div>", //设置文本标注内容
					// 	direction: 'top' //设置文本标注方位
					// });
					// this.setTop(true)
					// let { lng, lat } = this.getPosition()
					// map.setCenter([lng, lat]); //设置地图中心点
				})
				return marker;
			} else {
				return {}
			}
		})
		
		map.add(addMarkerList);	
		
	   // map.setCenter([locationList[0].geometry.coordinates[0], locationList[0].geometry.coordinates[1]]); //设置地图中心点
		//设置地图显示范围
		var mybounds = new AMap.Bounds([locationList.bbox[0], locationList.bbox[1]], [locationList.bbox[2], locationList.bbox[3]]);
		map.setBounds(mybounds);
		
	},
	// moveCenter(long, lat){
	// 	map.setCenter(long, lat); //设置地图中心点
	// },
	//点击列表某条数据渲染地图数据 不请求接口
	currentMarker(currentData,title){
		let images;
		map.clearMap(); //清除marker
		images = new AMap.Icon({
			size: new AMap.Size(25, 34),
			image: iconMap[currentData.monitorTypeCode],
			imageSize: new AMap.Size(30, 30),
		});
		marker = new AMap.Marker({
			position: [currentData.lgt * 1,currentData.lat * 1],
			icon:  images,
		})
		marker.on('click', function(e) {	
			this.setLabel({
				 offset: new AMap.Pixel(0, -10),  //设置文本标注偏移量
				content: "<div class='info'>"+title+"<i></i></div>", //设置文本标注内容
				direction: 'top' //设置文本标注方位
			});
		})
		
		map.add(marker);	
		map.setCenter([currentData.lgt, currentData.lat]); //设置地图中心点
	},
	destroyMap(){
		map && map.destroy();
	}
}
